package com.leyou.search.web;

import com.leyou.common.vo.PageResult;
import com.leyou.search.pojo.Goods;
import com.leyou.search.service.SearchService;
import com.leyou.search.utils.SearchRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/5/6 0006
 * Time: 22:35
 */

@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    @PostMapping("page")
    public ResponseEntity<PageResult<Goods>> queryGoodsByPage(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.queryGoodsByPage(searchRequest));
    }

    @PostMapping("page/price")
    public ResponseEntity<PageResult<Goods>> queryGoodsByPageAndPrice(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.queryGoodsByPageAndPrice(searchRequest));
    }

    @PostMapping("page/stock")
    public ResponseEntity<PageResult<Goods>> queryGoodsByPageAndStock(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.queryGoodsByPageAndStock(searchRequest));
    }

    @PostMapping("page/update")
    public ResponseEntity<PageResult<Goods>> queryGoodsByPageAndUpdate(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.queryGoodsByPageAndUpdate(searchRequest));
    }

    @PostMapping("filter")
    public ResponseEntity<Map<String, List<?>>> queryFilter(@RequestBody SearchRequest searchRequest) {
        return ResponseEntity.ok(searchService.queryFilter(searchRequest));
    }
}
